"use strict";
const common_vendor = require("./common/vendor.js");
const utils_auth_index = require("./utils/auth/index.js");
const loginPage = "/pages/common/login/index";
const whiteList = ["/", "/pages/common/login/index", "/pages/tab/home/index"];
function checkWhite(url) {
  const path = url.split("?")[0];
  return whiteList.includes(path);
}
const list = ["navigateTo", "redirectTo", "reLaunch", "switchTab"];
list.forEach((item) => {
  common_vendor.index.addInterceptor(item, {
    invoke(to) {
      if (utils_auth_index.getToken()) {
        if (to.url === loginPage)
          common_vendor.index.reLaunch({ url: "/" });
        return true;
      } else {
        if (checkWhite(to.url))
          return true;
        common_vendor.index.reLaunch({ url: loginPage });
        return false;
      }
    },
    fail(err) {
      console.log(err);
    }
  });
});
